<?php
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
require_once($GLOBALS['PAD']."Modules/MX23DF2S/modconf.mex");
MYTCONN();
	$MYT = $GLOBALS['MYT'];
form_pr('ExchangeInvoice','','','post'); 
mn_field('hidden','ED','OBJCTCL',$OBJCTCL,'','','','');?>
<div id="pr_exe"></div>
	<div style="margin:5px;border:2px #CCCCCC solid;padding:4px">Troca de Moeda</div>
<table width="100%"  border="0" cellpadding="3" cellspacing="1">
    <tr>
      <td colspan="2" rowspan="2" bgcolor="#F2F2F2"><div id="Exc_app"><?php include($MODPAD.'exc_exe/exe_input.mex'); ?></div></td>
      <td width="35%" rowspan="3" bgcolor="#F2F2F2"><div id="Exc_rate"></div></td>
      <td bgcolor="#F2F2F2"><?php
		 $CallRecipe = $MYT->db_array("SELECT * FROM exchange_operations 
		 WHERE main_office_ref = {$_SESSION[$SESSOF]} ORDER BY control_ref DESC LIMIT 0,1");
		if (!isset($CallRecipe[1]['control_ref']) || $CallRecipe[1]['control_ref'] == "") { 
		$tmp = $GLOBALS['MYT']->db_array("SELECT * FROM _tmp_exchange_recipes WHERE main_offices_ref = {$_SESSION[$SESSOF]}");
		$Control = $tmp[1]['initvalue'];
		} else {
		$Control = $CallRecipe[1]['control_ref']+1;
		}
	$Office = $GLOBALS['MYT']->db_array("SELECT * FROM systemoffice.main_offices WHERE ref = {$_SESSION[$SESSOF]}");
	if (!isset($_POST['TmpOp'])) {
	$MYT->db_query("INSERT INTO exchange_tmpops (RefUser, RefClient, Status) VALUES ({$_SESSION[$SESSID]},{$OBJCTCL},1)");
	$TmpOp = $MYT->db_array("SELECT ref FROM exchange_tmpops WHERE RefUser = {$_SESSION[$SESSID]} ORDER BY ref DESC LIMIT 0,1");
	$TmpOp = $TmpOp[1]['ref'];
	echo '<input value="'.$TmpOp.'" name="TmpOp" type="hidden">';
	} else {
	echo '<input value="'.$_POST['TmpOp'].'" name="TmpOp" type="hidden">';
	$TmpOp = $_POST['TmpOp'];
	}
	mn_field('hidden','ED','control_ref',$Control,'','','','');
	mn_field('hidden','ED','main_office_ref',$Office[1]['ref'],'','','','');
		echo 'N&uacute;mero da Operação: '.$Office[1]['office_number'].'-'.$Control;?></td>
    </tr>
    <tr>
      <td bgcolor="#F2F2F2">Data: <?php echo $sysTime; ?></td>
    </tr>
    <tr>
      <td colspan="2" bgcolor="#F2F2F2">
	  <div id="Exc_result"><?php include($GLOBALS['PAD'].'Modules/MX23DF2S/exc_exe/exe_result.mex');?></div></td>
      <td width="35%" bgcolor="#F2F2F2">Tipo:
      <?php 
	  mn_field('hselect','ED','operation_type','',"Compra;Venda#1;2",'','','" onchange="
	  document.ExchangeInvoice.action=\''.$MODURL.'exc_exe/exe_input.mex\';
	  subform(\'ExchangeInvoice\',\'Exc_app\');"'); ?></td>
    </tr>
</table>
<div id="Exc_register"></div>
</form>